CycleGAN, Image-to-Image Translation

In this notebook, we're going to define and train a CycleGAN to read in an image from a set $X$ and transform it so that it looks as if it belongs in set $Y$. Specifically, we'll look at a set of images of Yosemite national park taken either during the summer of winter. The seasons are our two domains!

The objective will be to train generators that learn to transform an image from domain $X$ into an image that looks like it came from domain $Y$ (and vice versa).

Some examples of image data in both sets are pictured below.

Unpaired Training Data

These images do not come with labels, but CycleGANs give us a way to learn the mapping between one image domain and another using an unsupervised approach. A CycleGAN is designed for image-to-image translation and it learns from unpaired training data. This means that in order to train a generator to translate images from domain $X$ to domain $Y$, we do not have to have exact correspondences between individual images in those domains. For example, in the paper that introduced CycleGANs, the authors are able to translate between images of horses and zebras, even though there are no images of a zebra in exactly the same position as a horse or with exactly the same background, etc. Thus, CycleGANs enable learning a mapping from one domain $X$ to another domain $Y$ without having to find perfectly-matched, training pairs!

CycleGAN and Notebook Structure

A CycleGAN is made of two types of networks: discriminators, and generators. In this example, the discriminators are responsible for classifying images as real or fake (for both $X$ and $Y$ kinds of images). The generators are responsible for generating convincing, fake images for both kinds of images.

This notebook will detail the steps you should take to define and train such a CycleGAN.

  1. You'll load in the image data using PyTorch's DataLoader class to efficiently read in images from a specified directory.
  2. Then, you'll be tasked with defining the CycleGAN architecture according to provided specifications. You'll define the discriminator and the generator models.
  3. You'll complete the training cycle by calculating the adversarial and cycle consistency losses for the generator and discriminator network and completing a number of training epochs. It's suggested that you enable GPU usage for training.
  4. Finally, you'll evaluate your model by looking at the loss over time and looking at sample, generated images.
In [4]:
import torch
torch.cuda.get_device_properties(device=None)
Out[4]:
_CudaDeviceProperties(name='GeForce GTX 1080', major=6, minor=1, total_memory=8192MB, multi_processor_count=20)

Load and Visualize the Data

We'll first load in and visualize the training data, importing the necessary libraries to do so.

If you are working locally, you'll need to download the data as a zip file by clicking here.

It may be named summer2winter-yosemite/ with a dash or an underscore, so take note, extract the data to your home directory and make sure the below image_dir matches. Then you can proceed with the following loading code.

In [1]:
# loading in and transforming data
import os
import torch
from torch.utils.data import DataLoader
import torchvision
import torchvision.datasets as datasets
import torchvision.transforms as transforms

# visualizing data
import matplotlib.pyplot as plt
import numpy as np
import warnings

%matplotlib inline

DataLoaders

The get_data_loader function returns training and test DataLoaders that can load data efficiently and in specified batches. The function has the following parameters:

  • image_type: summer or winter, the names of the directories where the X and Y images are stored
  • image_dir: name of the main image directory, which holds all training and test images
  • image_size: resized, square image dimension (all images will be resized to this dim)
  • batch_size: number of images in one batch of data

The test data is strictly for feeding to our generators, later on, so we can visualize some generated samples on fixed, test data.

You can see that this function is also responsible for making sure our images are of the right, square size (128x128x3) and converted into Tensor image types.

It's suggested that you use the default values of these parameters.

Note: If you are trying this code on a different set of data, you may get better results with larger image_size and batch_size parameters. If you change the batch_size, make sure that you create complete batches in the training loop otherwise you may get an error when trying to save sample data.

In [2]:
def get_data_loader(image_type, image_dir='summer2winter-yosemite', 
                    image_size=128, batch_size=16, num_workers=0):
    """Returns training and test data loaders for a given image type, either 'summer' or 'winter'. 
       These images will be resized to 128x128x3, by default, converted into Tensors, and normalized.
    """
    
    # resize and normalize the images
    transform = transforms.Compose([transforms.Resize(image_size), # resize to 128x128
                                    transforms.ToTensor()])

    # get training and test directories
    image_path = './' + image_dir
    train_path = os.path.join(image_path, image_type)
    test_path = os.path.join(image_path, 'test_{}'.format(image_type))

    # define datasets using ImageFolder
    train_dataset = datasets.ImageFolder(train_path, transform)
    test_dataset = datasets.ImageFolder(test_path, transform)

    # create and return DataLoaders
    train_loader = DataLoader(dataset=train_dataset, batch_size=batch_size, shuffle=True, num_workers=num_workers)
    test_loader = DataLoader(dataset=test_dataset, batch_size=batch_size, shuffle=False, num_workers=num_workers)

    return train_loader, test_loader
In [3]:
# Create train and test dataloaders for images from the two domains X and Y
# image_type = directory names for our data
dataloader_X, test_dataloader_X = get_data_loader(image_type='summer')
dataloader_Y, test_dataloader_Y = get_data_loader(image_type='winter')

Display some Training Images

Below we provide a function imshow that reshape some given images and converts them to NumPy images so that they can be displayed by plt. This cell should display a grid that contains a batch of image data from set $X$.

In [4]:
# helper imshow function
def imshow(img):
    npimg = img.numpy()
    plt.imshow(np.transpose(npimg, (1, 2, 0)))
    

# get some images from X
dataiter = iter(dataloader_X)
# the "_" is a placeholder for no labels
images, _ = dataiter.next()

# show images
fig = plt.figure(figsize=(12, 8))
imshow(torchvision.utils.make_grid(images))

Next, let's visualize a batch of images from set $Y$.

In [5]:
# get some images from Y
dataiter = iter(dataloader_Y)
images, _ = dataiter.next()

# show images
fig = plt.figure(figsize=(12,8))
imshow(torchvision.utils.make_grid(images))

Pre-processing: scaling from -1 to 1

We need to do a bit of pre-processing; we know that the output of our tanh activated generator will contain pixel values in a range from -1 to 1, and so, we need to rescale our training images to a range of -1 to 1. (Right now, they are in a range from 0-1.)

In [6]:
# current range
img = images[0]

print('Min: ', img.min())
print('Max: ', img.max())
Min:  tensor(0.0667)
Max:  tensor(0.9451)
In [7]:
# helper scale function
def scale(x, feature_range=(-1, 1)):
    ''' Scale takes in an image x and returns that image, scaled
       with a feature_range of pixel values from -1 to 1. 
       This function assumes that the input x is already scaled from 0-1.'''
    
    # scale from 0-1 to feature_range
    min, max = feature_range
    x = x * (max - min) + min
    return x
In [8]:
# scaled range
scaled_img = scale(img)

print('Scaled min: ', scaled_img.min())
print('Scaled max: ', scaled_img.max())
Scaled min:  tensor(-0.8667)
Scaled max:  tensor(0.8902)

Define the Model

A CycleGAN is made of two discriminator and two generator networks.

Discriminators

The discriminators, $D_X$ and $D_Y$, in this CycleGAN are convolutional neural networks that see an image and attempt to classify it as real or fake. In this case, real is indicated by an output close to 1 and fake as close to 0. The discriminators have the following architecture:

This network sees a 128x128x3 image, and passes it through 5 convolutional layers that downsample the image by a factor of 2. The first four convolutional layers have a BatchNorm and ReLu activation function applied to their output, and the last acts as a classification layer that outputs one value.

Convolutional Helper Function

To define the discriminators, you're expected to use the provided conv function, which creates a convolutional layer + an optional batch norm layer.

In [9]:
import torch.nn as nn
import torch.nn.functional as F

# helper conv function
def conv(in_channels, out_channels, kernel_size, stride=2, padding=1, batch_norm=True):
    """Creates a convolutional layer, with optional batch normalization.
    """
    layers = []
    conv_layer = nn.Conv2d(in_channels=in_channels, out_channels=out_channels, 
                           kernel_size=kernel_size, stride=stride, padding=padding, bias=False)
    
    layers.append(conv_layer)

    if batch_norm:
        layers.append(nn.BatchNorm2d(out_channels))
    return nn.Sequential(*layers)

Define the Discriminator Architecture

Your task is to fill in the __init__ function with the specified 5 layer conv net architecture. Both $D_X$ and $D_Y$ have the same architecture, so we only need to define one class, and later instantiate two discriminators.

It's recommended that you use a kernel size of 4x4 and use that to determine the correct stride and padding size for each layer. This Stanford resource may also help in determining stride and padding sizes.

  • Define your convolutional layers in __init__
  • Then fill in the forward behavior of the network

The forward function defines how an input image moves through the discriminator, and the most important thing is to pass it through your convolutional layers in order, with a ReLu activation function applied to all but the last layer.

You should not apply a sigmoid activation function to the output, here, and that is because we are planning on using a squared error loss for training. And you can read more about this loss function, later in the notebook.

In [10]:
class Discriminator(nn.Module):
    
    def __init__(self, conv_dim=64):
        super(Discriminator, self).__init__()

        # Define all convolutional layers
        # Should accept an RGB image as input and output a single value
        self.conv1 = conv(3, conv_dim, 4, batch_norm=False) ## 64X64
        self.conv2 = conv(64, conv_dim*2, 4) ## 32x32
        self.conv3 = conv(128, conv_dim*4, 4) ### 16x16
        self.conv4 = conv(256, conv_dim*8, 4) ## 8x8
        self.conv5 = conv(conv_dim*8, 1, 4, stride=1, batch_norm=False)
    def forward(self, x):
        # define feedforward behavior
        x = F.relu(self.conv1(x))
        x = F.relu(self.conv2(x))
        x = F.relu(self.conv3(x))
        x = F.relu(self.conv4(x))
        x = self.conv5(x)
        return x

Generators

The generators, G_XtoY and G_YtoX (sometimes called F), are made of an encoder, a conv net that is responsible for turning an image into a smaller feature representation, and a decoder, a transpose_conv net that is responsible for turning that representation into an transformed image. These generators, one from XtoY and one from YtoX, have the following architecture:

This network sees a 128x128x3 image, compresses it into a feature representation as it goes through three convolutional layers and reaches a series of residual blocks. It goes through a few (typically 6 or more) of these residual blocks, then it goes through three transpose convolutional layers (sometimes called de-conv layers) which upsample the output of the resnet blocks and create a new image!

Note that most of the convolutional and transpose-convolutional layers have BatchNorm and ReLu functions applied to their outputs with the exception of the final transpose convolutional layer, which has a tanh activation function applied to the output. Also, the residual blocks are made of convolutional and batch normalization layers, which we'll go over in more detail, next.


Residual Block Class

To define the generators, you're expected to define a ResidualBlock class which will help you connect the encoder and decoder portions of the generators. You might be wondering, what exactly is a Resnet block? It may sound familiar from something like ResNet50 for image classification, pictured below.

ResNet blocks rely on connecting the output of one layer with the input of an earlier layer. The motivation for this structure is as follows: very deep neural networks can be difficult to train. Deeper networks are more likely to have vanishing or exploding gradients and, therefore, have trouble reaching convergence; batch normalization helps with this a bit. However, during training, we often see that deep networks respond with a kind of training degradation. Essentially, the training accuracy stops improving and gets saturated at some point during training. In the worst cases, deep models would see their training accuracy actually worsen over time!

One solution to this problem is to use Resnet blocks that allow us to learn so-called residual functions as they are applied to layer inputs. You can read more about this proposed architecture in the paper, Deep Residual Learning for Image Recognition by Kaiming He et. al, and the below image is from that paper.

Residual Functions

Usually, when we create a deep learning model, the model (several layers with activations applied) is responsible for learning a mapping, M, from an input x to an output y.

M(x) = y (Equation 1)

Instead of learning a direct mapping from x to y, we can instead define a residual function

F(x) = M(x) - x

This looks at the difference between a mapping applied to x and the original input, x. F(x) is, typically, two convolutional layers + normalization layer and a ReLu in between. These convolutional layers should have the same number of inputs as outputs. This mapping can then be written as the following; a function of the residual function and the input x. The addition step creates a kind of loop that connects the input x to the output, y:

M(x) = F(x) + x (Equation 2) or

y = F(x) + x (Equation 3)

Optimizing a Residual Function

The idea is that it is easier to optimize this residual function F(x) than it is to optimize the original mapping M(x). Consider an example; what if we want y = x?

From our first, direct mapping equation, Equation 1, we could set M(x) = x but it is easier to solve the residual equation F(x) = 0, which, when plugged in to Equation 3, yields y = x.

Defining the ResidualBlock Class

To define the ResidualBlock class, we'll define residual functions (a series of layers), apply them to an input x and add them to that same input. This is defined just like any other neural network, with an __init__ function and the addition step in the forward function.

In our case, you'll want to define the residual block as:

  • Two convolutional layers with the same size input and output
  • Batch normalization applied to the outputs of the convolutional layers
  • A ReLu function on the output of the first convolutional layer

Then, in the forward function, add the input x to this residual block. Feel free to use the helper conv function from above to create this block.

In [11]:
# residual block class
class ResidualBlock(nn.Module):
    """Defines a residual block.
       This adds an input x to a convolutional layer (applied to x) with the same size input and output.
       These blocks allow a model to learn an effective transformation from one domain to another.
    """
    def __init__(self, conv_dim):
        super(ResidualBlock, self).__init__()
        # conv_dim = number of inputs  
        self.conv1 = conv(conv_dim, conv_dim, 3, stride=1)
        self.conv2 = conv(conv_dim, conv_dim, 3, stride=1)
        # define two convolutional layers + batch normalization that will act as our residual function, F(x)
        # layers should have the same shape input as output; I suggest a kernel_size of 3
        
        
    def forward(self, x):
        # apply a ReLu activation the outputs of the first layer
        # return a summed output, x + resnet_block(x)
        out_1 = F.relu(self.conv1(x))
        out_2 = x + self.conv2(out_1) 
        return out_2
    

Transpose Convolutional Helper Function

To define the generators, you're expected to use the above conv function, ResidualBlock class, and the below deconv helper function, which creates a transpose convolutional layer + an optional batchnorm layer.

In [12]:
# helper deconv function
def deconv(in_channels, out_channels, kernel_size, stride=2, padding=1, batch_norm=True):
    """Creates a transpose convolutional layer, with optional batch normalization.
    """
    layers = []
    # append transpose conv layer
    layers.append(nn.ConvTranspose2d(in_channels, out_channels, kernel_size, stride, padding, bias=False))
    # optional batch norm layer
    if batch_norm:
        layers.append(nn.BatchNorm2d(out_channels))
    return nn.Sequential(*layers)

Define the Generator Architecture

  • Complete the __init__ function with the specified 3 layer encoder convolutional net, a series of residual blocks (the number of which is given by n_res_blocks), and then a 3 layer decoder transpose convolutional net.
  • Then complete the forward function to define the forward behavior of the generators. Recall that the last layer has a tanh activation function.

Both $G_{XtoY}$ and $G_{YtoX}$ have the same architecture, so we only need to define one class, and later instantiate two generators.

In [13]:
class CycleGenerator(nn.Module):
    
    def __init__(self, conv_dim=64, n_res_blocks=6):
        super(CycleGenerator, self).__init__()

        # 1. Define the encoder part of the generator
        self.encoder = nn.Sequential(conv(3, conv_dim, 4 ), nn.ReLU(),### 64x64x64
                                     conv(conv_dim, conv_dim*2, 4 ), nn.ReLU(), ## 32x32x128
                                     conv(conv_dim*2, conv_dim*4, 4 ),  nn.ReLU() ### 16x16x256
                                    )   

        # 2. Define the resnet part of the generator
        seq_layers = []
        for block in range(n_res_blocks):
            seq_layers.append(ResidualBlock(conv_dim*4))
        self.residualblocks = nn.Sequential(*seq_layers)

        # 3. Define the decoder part of the generator
        self.decoder = nn.Sequential( deconv(conv_dim*4, conv_dim*2, 4),  nn.ReLU(), 
                                      deconv(conv_dim*2, conv_dim, 4),  nn.ReLU(),
                                      deconv(conv_dim, 3, 4, batch_norm=False), nn.Tanh()
                                    )

    def forward(self, x):
        """Given an image x, returns a transformed image."""
        # define feedforward behavior, applying activations as necessary
        x = self.encoder(x)
        x = self.residualblocks(x)
        x = self.decoder(x)

        return x

Create the complete network

Using the classes you defined earlier, you can define the discriminators and generators necessary to create a complete CycleGAN. The given parameters should work for training.

First, create two discriminators, one for checking if $X$ sample images are real, and one for checking if $Y$ sample images are real. Then the generators. Instantiate two of them, one for transforming a painting into a realistic photo and one for transforming a photo into into a painting.

In [14]:
def create_model(g_conv_dim=64, d_conv_dim=64, n_res_blocks=6):
    """Builds the generators and discriminators."""
    
    # Instantiate generators
    G_XtoY = CycleGenerator(conv_dim=g_conv_dim, n_res_blocks=n_res_blocks)
    G_YtoX = CycleGenerator(conv_dim=g_conv_dim, n_res_blocks=n_res_blocks)
    # Instantiate discriminators
    D_X = Discriminator(conv_dim=d_conv_dim)
    D_Y = Discriminator(conv_dim=d_conv_dim)

    # move models to GPU, if available
    if torch.cuda.is_available():
        device = torch.device("cuda:0")
        G_XtoY.to(device)
        G_YtoX.to(device)
        D_X.to(device)
        D_Y.to(device)
        print('Models moved to GPU.')
    else:
        print('Only CPU available.')

    return G_XtoY, G_YtoX, D_X, D_Y
In [15]:
# call the function to get models
G_XtoY, G_YtoX, D_X, D_Y = create_model()
Models moved to GPU.

Check that you've implemented this correctly

The function create_model should return the two generator and two discriminator networks. After you've defined these discriminator and generator components, it's good practice to check your work. The easiest way to do this is to print out your model architecture and read through it to make sure the parameters are what you expected. The next cell will print out their architectures.

In [16]:
# helper function for printing the model architecture
def print_models(G_XtoY, G_YtoX, D_X, D_Y):
    """Prints model information for the generators and discriminators.
    """
    print("                     G_XtoY                    ")
    print("-----------------------------------------------")
    print(G_XtoY)
    print()

    print("                     G_YtoX                    ")
    print("-----------------------------------------------")
    print(G_YtoX)
    print()

    print("                      D_X                      ")
    print("-----------------------------------------------")
    print(D_X)
    print()

    print("                      D_Y                      ")
    print("-----------------------------------------------")
    print(D_Y)
    print()
    

# print all of the models
print_models(G_XtoY, G_YtoX, D_X, D_Y)
                     G_XtoY                    
-----------------------------------------------
CycleGenerator(
  (encoder): Sequential(
    (0): Sequential(
      (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (1): ReLU()
    (2): Sequential(
      (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (3): ReLU()
    (4): Sequential(
      (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (5): ReLU()
  )
  (residualblocks): Sequential(
    (0): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (2): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (3): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (4): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (decoder): Sequential(
    (0): Sequential(
      (0): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (1): ReLU()
    (2): Sequential(
      (0): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (3): ReLU()
    (4): Sequential(
      (0): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    )
    (5): Tanh()
  )
)

                     G_YtoX                    
-----------------------------------------------
CycleGenerator(
  (encoder): Sequential(
    (0): Sequential(
      (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (1): ReLU()
    (2): Sequential(
      (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (3): ReLU()
    (4): Sequential(
      (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (5): ReLU()
  )
  (residualblocks): Sequential(
    (0): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (1): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (2): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (3): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (4): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
    (5): ResidualBlock(
      (conv1): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
      (conv2): Sequential(
        (0): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False)
        (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
      )
    )
  )
  (decoder): Sequential(
    (0): Sequential(
      (0): ConvTranspose2d(256, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (1): ReLU()
    (2): Sequential(
      (0): ConvTranspose2d(128, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
      (1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
    )
    (3): ReLU()
    (4): Sequential(
      (0): ConvTranspose2d(64, 3, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    )
    (5): Tanh()
  )
)

                      D_X                      
-----------------------------------------------
Discriminator(
  (conv1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
  (conv2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv4): Sequential(
    (0): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv5): Sequential(
    (0): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
  )
)

                      D_Y                      
-----------------------------------------------
Discriminator(
  (conv1): Sequential(
    (0): Conv2d(3, 64, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
  )
  (conv2): Sequential(
    (0): Conv2d(64, 128, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv3): Sequential(
    (0): Conv2d(128, 256, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv4): Sequential(
    (0): Conv2d(256, 512, kernel_size=(4, 4), stride=(2, 2), padding=(1, 1), bias=False)
    (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
  )
  (conv5): Sequential(
    (0): Conv2d(512, 1, kernel_size=(4, 4), stride=(1, 1), padding=(1, 1), bias=False)
  )
)

Discriminator and Generator Losses

Computing the discriminator and the generator losses are key to getting a CycleGAN to train.

Image from original paper by Jun-Yan Zhu et. al.

  • The CycleGAN contains two mapping functions $G: X \rightarrow Y$ and $F: Y \rightarrow X$, and associated adversarial discriminators $D_Y$ and $D_X$. (a) $D_Y$ encourages $G$ to translate $X$ into outputs indistinguishable from domain $Y$, and vice versa for $D_X$ and $F$.

  • To further regularize the mappings, we introduce two cycle consistency losses that capture the intuition that if we translate from one domain to the other and back again we should arrive at where we started. (b) Forward cycle-consistency loss and (c) backward cycle-consistency loss.

Least Squares GANs

We've seen that regular GANs treat the discriminator as a classifier with the sigmoid cross entropy loss function. However, this loss function may lead to the vanishing gradients problem during the learning process. To overcome such a problem, we'll use a least squares loss function for the discriminator. This structure is also referred to as a least squares GAN or LSGAN, and you can read the original paper on LSGANs, here. The authors show that LSGANs are able to generate higher quality images than regular GANs and that this loss type is a bit more stable during training!

Discriminator Losses

The discriminator losses will be mean squared errors between the output of the discriminator, given an image, and the target value, 0 or 1, depending on whether it should classify that image as fake or real. For example, for a real image, x, we can train $D_X$ by looking at how close it is to recognizing and image x as real using the mean squared error:

out_x = D_X(x)
real_err = torch.mean((out_x-1)**2)

Generator Losses

Calculating the generator losses will look somewhat similar to calculating the discriminator loss; there will still be steps in which you generate fake images that look like they belong to the set of $X$ images but are based on real images in set $Y$, and vice versa. You'll compute the "real loss" on those generated images by looking at the output of the discriminator as it's applied to these fake images; this time, your generator aims to make the discriminator classify these fake images as real images.

Cycle Consistency Loss

In addition to the adversarial losses, the generator loss terms will also include the cycle consistency loss. This loss is a measure of how good a reconstructed image is, when compared to an original image.

Say you have a fake, generated image, x_hat, and a real image, y. You can get a reconstructed y_hat by applying G_XtoY(x_hat) = y_hat and then check to see if this reconstruction y_hat and the orginal image y match. For this, we recommed calculating the L1 loss, which is an absolute difference, between reconstructed and real images. You may also choose to multiply this loss by some weight value lambda_weight to convey its importance.

The total generator loss will be the sum of the generator losses and the forward and backward cycle consistency losses.


Define Loss Functions

To help us calculate the discriminator and gnerator losses during training, let's define some helpful loss functions. Here, we'll define three.

  1. real_mse_loss that looks at the output of a discriminator and returns the error based on how close that output is to being classified as real. This should be a mean squared error.
  2. fake_mse_loss that looks at the output of a discriminator and returns the error based on how close that output is to being classified as fake. This should be a mean squared error.
  3. cycle_consistency_loss that looks at a set of real image and a set of reconstructed/generated images, and returns the mean absolute error between them. This has a lambda_weight parameter that will weight the mean absolute error in a batch.

It's recommended that you take a look at the original, CycleGAN paper to get a starting value for lambda_weight.

In [17]:
def real_mse_loss(D_out):
    # how close is the produced output from being "real"?
    real_err = torch.mean((D_out-1)**2)
    return real_err

def fake_mse_loss(D_out):
    # how close is the produced output from being "fake"?
    fake_err = torch.mean((D_out-0)**2)
    return fake_err

def cycle_consistency_loss(real_im, reconstructed_im, lambda_weight):
    # calculate reconstruction loss 
    # return weighted loss
    err = torch.mean(torch.abs(real_im - reconstructed_im))*lambda_weight
    return err

Define the Optimizers

Next, let's define how this model will update its weights. This, like the GANs you may have seen before, uses Adam optimizers for the discriminator and generator. It's again recommended that you take a look at the original, CycleGAN paper to get starting hyperparameter values.

In [18]:
import torch.optim as optim

# hyperparams for Adam optimizers
lr= 0.0002
beta1=0.5
beta2= 0.999

g_params = list(G_XtoY.parameters()) + list(G_YtoX.parameters())  # Get generator parameters

# Create optimizers for the generators and discriminators
g_optimizer = optim.Adam(g_params, lr, [beta1, beta2])
d_x_optimizer = optim.Adam(D_X.parameters(), lr, [beta1, beta2])
d_y_optimizer = optim.Adam(D_Y.parameters(), lr, [beta1, beta2])

Training a CycleGAN

When a CycleGAN trains, and sees one batch of real images from set $X$ and $Y$, it trains by performing the following steps:

Training the Discriminators

  1. Compute the discriminator $D_X$ loss on real images
  2. Generate fake images that look like domain $X$ based on real images in domain $Y$
  3. Compute the fake loss for $D_X$
  4. Compute the total loss and perform backpropagation and $D_X$ optimization
  5. Repeat steps 1-4 only with $D_Y$ and your domains switched!

Training the Generators

  1. Generate fake images that look like domain $X$ based on real images in domain $Y$
  2. Compute the generator loss based on how $D_X$ responds to fake $X$
  3. Generate reconstructed $\hat{Y}$ images based on the fake $X$ images generated in step 1
  4. Compute the cycle consistency loss by comparing the reconstructions with real $Y$ images
  5. Repeat steps 1-4 only swapping domains
  6. Add up all the generator and reconstruction losses and perform backpropagation + optimization

Saving Your Progress

A CycleGAN repeats its training process, alternating between training the discriminators and the generators, for a specified number of training iterations. You've been given code that will save some example generated images that the CycleGAN has learned to generate after a certain number of training iterations. Along with looking at the losses, these example generations should give you an idea of how well your network has trained.

Below, you may choose to keep all default parameters; your only task is to calculate the appropriate losses and complete the training cycle.

In [19]:
# import save code
from helpers import save_samples, checkpoint, get_version
In [20]:
# train the network
def training_loop(dataloader_X, dataloader_Y, test_dataloader_X, test_dataloader_Y, 
                  n_epochs=1000):
    
    print_every=10
    
    # keep track of losses over time
    losses = []

    test_iter_X = iter(test_dataloader_X)
    test_iter_Y = iter(test_dataloader_Y)

    # Get some fixed data from domains X and Y for sampling. These are images that are held
    # constant throughout training, that allow us to inspect the model's performance.
    fixed_X = test_iter_X.next()[0]
    fixed_Y = test_iter_Y.next()[0]
    fixed_X = scale(fixed_X) # make sure to scale to a range -1 to 1
    fixed_Y = scale(fixed_Y)

    # batches per epoch
    iter_X = iter(dataloader_X)
    iter_Y = iter(dataloader_Y)
    batches_per_epoch = min(len(iter_X), len(iter_Y))

    for epoch in range(1, n_epochs+1):

        # Reset iterators for each epoch
        if epoch % batches_per_epoch == 0:
            iter_X = iter(dataloader_X)
            iter_Y = iter(dataloader_Y)

        images_X, _ = iter_X.next()
        images_X = scale(images_X) # make sure to scale to a range -1 to 1

        images_Y, _ = iter_Y.next()
        images_Y = scale(images_Y)
        
        # move images to GPU if available (otherwise stay on CPU)
        device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
        images_X = images_X.to(device)
        images_Y = images_Y.to(device)


        # ============================================
        #            TRAIN THE DISCRIMINATORS
        # ============================================

        ##   First: D_X, real and fake loss components   ##

        # 1. Compute the discriminator losses on real images
        
        # 2. Generate fake images that look like domain X based on real images in domain Y

        # 3. Compute the fake loss for D_X
        
        # 4. Compute the total loss and perform backprop
        d_x_optimizer.zero_grad()
        
        d_out_real = D_X(images_X)
        fake_X = G_YtoX(images_Y)
        d_out_fake = D_X(fake_X)
        d_x_loss = real_mse_loss(d_out_real) + fake_mse_loss(d_out_fake) 
        d_x_loss.backward()
        d_x_optimizer.step()

        
        ##   Second: D_Y, real and fake loss components   ##
        d_y_optimizer.zero_grad()
        
        d_out_real = D_Y(images_Y)
        fake_Y = G_XtoY(images_X)
        d_out_fake = D_Y(fake_Y)
        d_y_loss = real_mse_loss(d_out_real) + fake_mse_loss(d_out_fake)
        
        
        d_y_loss.backward()
        d_y_optimizer.step()
        


        # =========================================
        #            TRAIN THE GENERATORS
        # =========================================

        ##    First: generate fake X images and reconstructed Y images    ##

        # 1. Generate fake images that look like domain X based on real images in domain Y

        # 2. Compute the generator loss based on domain X

        # 3. Create a reconstructed y
        
        # 4. Compute the cycle consistency loss (the reconstruction loss)
        g_optimizer.zero_grad()
        
        fake_X = G_YtoX(images_Y)
        d_out_fake = D_X(fake_X)
        g_x_loss = real_mse_loss(d_out_fake)
        
        fake_Y = G_XtoY(fake_X)
        c_y_loss = cycle_consistency_loss(images_Y, fake_Y, 10)

        ##    Second: generate fake Y images and reconstructed X images    ##
        fake_Y = G_XtoY(images_X)
        d_out_fake = D_Y(fake_Y)
        g_y_loss = real_mse_loss(d_out_fake)
        
        fake_X = G_YtoX(fake_Y)
        c_x_loss = cycle_consistency_loss(images_X, fake_X, 10)
        # 5. Add up all generator and reconstructed losses and perform backprop
        g_total_loss = g_x_loss + c_y_loss + g_y_loss + c_x_loss
        
        
        g_total_loss.backward()
        g_optimizer.step()

        
        # Print the log info
        if epoch % print_every == 0:
            # append real and fake discriminator losses and the generator loss
            losses.append((d_x_loss.item(), d_y_loss.item(), g_total_loss.item()))
            print('Epoch [{:5d}/{:5d}] | d_X_loss: {:6.4f} | d_Y_loss: {:6.4f} | g_total_loss: {:6.4f}'.format(
                    epoch, n_epochs, d_x_loss.item(), d_y_loss.item(), g_total_loss.item()))

            
        sample_every=100
        # Save the generated samples
        if epoch % sample_every == 0:
            G_YtoX.eval() # set generators to eval mode for sample generation
            G_XtoY.eval()
            save_samples(epoch, fixed_Y, fixed_X, G_YtoX, G_XtoY, batch_size=16)
            G_YtoX.train()
            G_XtoY.train()

        # uncomment these lines, if you want to save your model
        checkpoint_every=1000
         # Save the model parameters
        if epoch % checkpoint_every == 0:
            checkpoint(epoch, G_XtoY, G_YtoX, D_X, D_Y)

    return losses
In [21]:
get_version()
Out[21]:
'latest'
In [22]:
n_epochs = 4000 # keep this small when testing if a model first works, then increase it to >=1000

losses = training_loop(dataloader_X, dataloader_Y, test_dataloader_X, test_dataloader_Y, n_epochs=n_epochs)
Epoch [   10/ 4000] | d_X_loss: 0.2274 | d_Y_loss: 0.3037 | g_total_loss: 9.5368
Epoch [   20/ 4000] | d_X_loss: 0.3525 | d_Y_loss: 0.2185 | g_total_loss: 7.9238
Epoch [   30/ 4000] | d_X_loss: 0.2942 | d_Y_loss: 0.6602 | g_total_loss: 6.6786
Epoch [   40/ 4000] | d_X_loss: 0.5795 | d_Y_loss: 0.4229 | g_total_loss: 5.9607
Epoch [   50/ 4000] | d_X_loss: 0.4857 | d_Y_loss: 0.4564 | g_total_loss: 5.3828
Epoch [   60/ 4000] | d_X_loss: 0.5753 | d_Y_loss: 0.4565 | g_total_loss: 5.6679
Epoch [   70/ 4000] | d_X_loss: 0.4263 | d_Y_loss: 0.3323 | g_total_loss: 5.0167
Epoch [   80/ 4000] | d_X_loss: 0.4088 | d_Y_loss: 0.4374 | g_total_loss: 4.5914
Epoch [   90/ 4000] | d_X_loss: 0.4319 | d_Y_loss: 0.4991 | g_total_loss: 4.8049
Epoch [  100/ 4000] | d_X_loss: 0.4809 | d_Y_loss: 0.3844 | g_total_loss: 4.8066
Saved samples_cyclegan\sample-000100-X-Y.png
Saved samples_cyclegan\sample-000100-Y-X.png
Epoch [  110/ 4000] | d_X_loss: 0.3879 | d_Y_loss: 0.4396 | g_total_loss: 5.0025
Epoch [  120/ 4000] | d_X_loss: 0.5641 | d_Y_loss: 0.3984 | g_total_loss: 4.3742
Epoch [  130/ 4000] | d_X_loss: 0.4136 | d_Y_loss: 0.4188 | g_total_loss: 4.3045
Epoch [  140/ 4000] | d_X_loss: 0.5021 | d_Y_loss: 0.3900 | g_total_loss: 4.4301
Epoch [  150/ 4000] | d_X_loss: 0.4179 | d_Y_loss: 0.4428 | g_total_loss: 4.6436
Epoch [  160/ 4000] | d_X_loss: 0.6261 | d_Y_loss: 0.4431 | g_total_loss: 5.4674
Epoch [  170/ 4000] | d_X_loss: 0.4052 | d_Y_loss: 0.4980 | g_total_loss: 5.0228
Epoch [  180/ 4000] | d_X_loss: 0.4244 | d_Y_loss: 0.3153 | g_total_loss: 4.4146
Epoch [  190/ 4000] | d_X_loss: 0.3911 | d_Y_loss: 0.3984 | g_total_loss: 4.8323
Epoch [  200/ 4000] | d_X_loss: 0.3033 | d_Y_loss: 0.4127 | g_total_loss: 4.3949
Saved samples_cyclegan\sample-000200-X-Y.png
Saved samples_cyclegan\sample-000200-Y-X.png
Epoch [  210/ 4000] | d_X_loss: 0.4406 | d_Y_loss: 0.2820 | g_total_loss: 4.4690
Epoch [  220/ 4000] | d_X_loss: 0.3840 | d_Y_loss: 0.4334 | g_total_loss: 4.5329
Epoch [  230/ 4000] | d_X_loss: 0.4904 | d_Y_loss: 0.4459 | g_total_loss: 4.2830
Epoch [  240/ 4000] | d_X_loss: 0.3683 | d_Y_loss: 0.3947 | g_total_loss: 4.6536
Epoch [  250/ 4000] | d_X_loss: 0.3840 | d_Y_loss: 0.4311 | g_total_loss: 4.0042
Epoch [  260/ 4000] | d_X_loss: 0.4525 | d_Y_loss: 0.3960 | g_total_loss: 5.0593
Epoch [  270/ 4000] | d_X_loss: 0.3960 | d_Y_loss: 0.3865 | g_total_loss: 4.4206
Epoch [  280/ 4000] | d_X_loss: 0.4310 | d_Y_loss: 0.2775 | g_total_loss: 4.1824
Epoch [  290/ 4000] | d_X_loss: 0.4640 | d_Y_loss: 0.4617 | g_total_loss: 3.7531
Epoch [  300/ 4000] | d_X_loss: 0.4923 | d_Y_loss: 0.3158 | g_total_loss: 4.5329
Saved samples_cyclegan\sample-000300-X-Y.png
Saved samples_cyclegan\sample-000300-Y-X.png
Epoch [  310/ 4000] | d_X_loss: 0.3302 | d_Y_loss: 0.3959 | g_total_loss: 4.5784
Epoch [  320/ 4000] | d_X_loss: 0.3617 | d_Y_loss: 0.4366 | g_total_loss: 4.4522
Epoch [  330/ 4000] | d_X_loss: 0.4308 | d_Y_loss: 0.4388 | g_total_loss: 3.8912
Epoch [  340/ 4000] | d_X_loss: 0.3970 | d_Y_loss: 0.3681 | g_total_loss: 4.7564
Epoch [  350/ 4000] | d_X_loss: 0.2598 | d_Y_loss: 0.4828 | g_total_loss: 4.3427
Epoch [  360/ 4000] | d_X_loss: 0.2701 | d_Y_loss: 0.3544 | g_total_loss: 4.4839
Epoch [  370/ 4000] | d_X_loss: 0.4278 | d_Y_loss: 0.3602 | g_total_loss: 4.5334
Epoch [  380/ 4000] | d_X_loss: 0.5599 | d_Y_loss: 0.5043 | g_total_loss: 3.6782
Epoch [  390/ 4000] | d_X_loss: 0.3967 | d_Y_loss: 0.3621 | g_total_loss: 3.8639
Epoch [  400/ 4000] | d_X_loss: 0.4479 | d_Y_loss: 0.7317 | g_total_loss: 3.9912
Saved samples_cyclegan\sample-000400-X-Y.png
Saved samples_cyclegan\sample-000400-Y-X.png
Epoch [  410/ 4000] | d_X_loss: 0.5306 | d_Y_loss: 0.4542 | g_total_loss: 5.0664
Epoch [  420/ 4000] | d_X_loss: 0.4866 | d_Y_loss: 0.4148 | g_total_loss: 4.4632
Epoch [  430/ 4000] | d_X_loss: 0.3652 | d_Y_loss: 0.3207 | g_total_loss: 4.0630
Epoch [  440/ 4000] | d_X_loss: 0.4069 | d_Y_loss: 0.5022 | g_total_loss: 3.9666
Epoch [  450/ 4000] | d_X_loss: 0.3586 | d_Y_loss: 0.4362 | g_total_loss: 3.8099
Epoch [  460/ 4000] | d_X_loss: 0.6053 | d_Y_loss: 0.3780 | g_total_loss: 5.0551
Epoch [  470/ 4000] | d_X_loss: 0.5031 | d_Y_loss: 0.3508 | g_total_loss: 4.7798
Epoch [  480/ 4000] | d_X_loss: 0.2567 | d_Y_loss: 0.2581 | g_total_loss: 4.5358
Epoch [  490/ 4000] | d_X_loss: 0.2820 | d_Y_loss: 0.4696 | g_total_loss: 3.8356
Epoch [  500/ 4000] | d_X_loss: 0.3891 | d_Y_loss: 0.5804 | g_total_loss: 3.6804
Saved samples_cyclegan\sample-000500-X-Y.png
Saved samples_cyclegan\sample-000500-Y-X.png
Epoch [  510/ 4000] | d_X_loss: 0.4218 | d_Y_loss: 0.4001 | g_total_loss: 4.7057
Epoch [  520/ 4000] | d_X_loss: 0.4130 | d_Y_loss: 0.4585 | g_total_loss: 3.8106
Epoch [  530/ 4000] | d_X_loss: 0.3394 | d_Y_loss: 0.4074 | g_total_loss: 3.8679
Epoch [  540/ 4000] | d_X_loss: 0.4627 | d_Y_loss: 0.4015 | g_total_loss: 4.3886
Epoch [  550/ 4000] | d_X_loss: 0.5371 | d_Y_loss: 0.4694 | g_total_loss: 2.8965
Epoch [  560/ 4000] | d_X_loss: 0.3202 | d_Y_loss: 0.3365 | g_total_loss: 4.7009
Epoch [  570/ 4000] | d_X_loss: 0.3954 | d_Y_loss: 0.3702 | g_total_loss: 4.6913
Epoch [  580/ 4000] | d_X_loss: 0.4199 | d_Y_loss: 0.3526 | g_total_loss: 4.7812
Epoch [  590/ 4000] | d_X_loss: 0.5865 | d_Y_loss: 0.3537 | g_total_loss: 3.5893
Epoch [  600/ 4000] | d_X_loss: 0.6674 | d_Y_loss: 0.4866 | g_total_loss: 4.8180
Saved samples_cyclegan\sample-000600-X-Y.png
Saved samples_cyclegan\sample-000600-Y-X.png
Epoch [  610/ 4000] | d_X_loss: 0.4529 | d_Y_loss: 0.5415 | g_total_loss: 4.0520
Epoch [  620/ 4000] | d_X_loss: 0.4764 | d_Y_loss: 0.3740 | g_total_loss: 3.8209
Epoch [  630/ 4000] | d_X_loss: 0.3846 | d_Y_loss: 0.4078 | g_total_loss: 4.2897
Epoch [  640/ 4000] | d_X_loss: 0.4115 | d_Y_loss: 0.5792 | g_total_loss: 3.4498
Epoch [  650/ 4000] | d_X_loss: 0.4624 | d_Y_loss: 0.4549 | g_total_loss: 3.4829
Epoch [  660/ 4000] | d_X_loss: 0.4523 | d_Y_loss: 0.4545 | g_total_loss: 5.0261
Epoch [  670/ 4000] | d_X_loss: 0.3877 | d_Y_loss: 0.4541 | g_total_loss: 5.9510
Epoch [  680/ 4000] | d_X_loss: 0.3790 | d_Y_loss: 0.4156 | g_total_loss: 3.9074
Epoch [  690/ 4000] | d_X_loss: 0.2180 | d_Y_loss: 0.4095 | g_total_loss: 4.1492
Epoch [  700/ 4000] | d_X_loss: 0.4461 | d_Y_loss: 0.4247 | g_total_loss: 4.5994
Saved samples_cyclegan\sample-000700-X-Y.png
Saved samples_cyclegan\sample-000700-Y-X.png
Epoch [  710/ 4000] | d_X_loss: 0.3457 | d_Y_loss: 0.3690 | g_total_loss: 3.6829
Epoch [  720/ 4000] | d_X_loss: 0.4796 | d_Y_loss: 0.4387 | g_total_loss: 4.4306
Epoch [  730/ 4000] | d_X_loss: 0.3120 | d_Y_loss: 0.3980 | g_total_loss: 4.1108
Epoch [  740/ 4000] | d_X_loss: 0.3478 | d_Y_loss: 0.3717 | g_total_loss: 4.1485
Epoch [  750/ 4000] | d_X_loss: 0.3439 | d_Y_loss: 0.3590 | g_total_loss: 3.8003
Epoch [  760/ 4000] | d_X_loss: 0.4929 | d_Y_loss: 0.3422 | g_total_loss: 4.1622
Epoch [  770/ 4000] | d_X_loss: 0.3313 | d_Y_loss: 0.3273 | g_total_loss: 3.8687
Epoch [  780/ 4000] | d_X_loss: 0.3635 | d_Y_loss: 0.2808 | g_total_loss: 3.6858
Epoch [  790/ 4000] | d_X_loss: 0.4166 | d_Y_loss: 0.3524 | g_total_loss: 4.0466
Epoch [  800/ 4000] | d_X_loss: 0.3652 | d_Y_loss: 0.3471 | g_total_loss: 4.3483
Saved samples_cyclegan\sample-000800-X-Y.png
Saved samples_cyclegan\sample-000800-Y-X.png
Epoch [  810/ 4000] | d_X_loss: 0.4298 | d_Y_loss: 0.3388 | g_total_loss: 4.1963
Epoch [  820/ 4000] | d_X_loss: 0.3445 | d_Y_loss: 0.7465 | g_total_loss: 3.6286
Epoch [  830/ 4000] | d_X_loss: 0.6689 | d_Y_loss: 0.3487 | g_total_loss: 3.4796
Epoch [  840/ 4000] | d_X_loss: 0.2402 | d_Y_loss: 0.3508 | g_total_loss: 3.9793
Epoch [  850/ 4000] | d_X_loss: 0.3190 | d_Y_loss: 0.3346 | g_total_loss: 3.8287
Epoch [  860/ 4000] | d_X_loss: 0.3269 | d_Y_loss: 0.2737 | g_total_loss: 3.5750
Epoch [  870/ 4000] | d_X_loss: 0.2777 | d_Y_loss: 0.3316 | g_total_loss: 4.1506
Epoch [  880/ 4000] | d_X_loss: 0.3770 | d_Y_loss: 0.2519 | g_total_loss: 3.7533
Epoch [  890/ 4000] | d_X_loss: 0.2495 | d_Y_loss: 0.5053 | g_total_loss: 3.6491
Epoch [  900/ 4000] | d_X_loss: 0.2442 | d_Y_loss: 0.2892 | g_total_loss: 4.4183
Saved samples_cyclegan\sample-000900-X-Y.png
Saved samples_cyclegan\sample-000900-Y-X.png
Epoch [  910/ 4000] | d_X_loss: 0.4602 | d_Y_loss: 0.4368 | g_total_loss: 3.8356
Epoch [  920/ 4000] | d_X_loss: 0.1822 | d_Y_loss: 0.3365 | g_total_loss: 4.6651
Epoch [  930/ 4000] | d_X_loss: 0.2368 | d_Y_loss: 0.4817 | g_total_loss: 5.3729
Epoch [  940/ 4000] | d_X_loss: 0.2499 | d_Y_loss: 0.2027 | g_total_loss: 3.8731
Epoch [  950/ 4000] | d_X_loss: 0.3189 | d_Y_loss: 0.3479 | g_total_loss: 4.7119
Epoch [  960/ 4000] | d_X_loss: 0.3456 | d_Y_loss: 0.2338 | g_total_loss: 3.3880
Epoch [  970/ 4000] | d_X_loss: 0.3707 | d_Y_loss: 0.3167 | g_total_loss: 3.7228
Epoch [  980/ 4000] | d_X_loss: 0.2336 | d_Y_loss: 0.3743 | g_total_loss: 3.9437
Epoch [  990/ 4000] | d_X_loss: 0.2653 | d_Y_loss: 0.4381 | g_total_loss: 4.0412
Epoch [ 1000/ 4000] | d_X_loss: 0.3453 | d_Y_loss: 0.4164 | g_total_loss: 3.7998
Saved samples_cyclegan\sample-001000-X-Y.png
Saved samples_cyclegan\sample-001000-Y-X.png
Epoch [ 1010/ 4000] | d_X_loss: 0.3387 | d_Y_loss: 0.4533 | g_total_loss: 4.0204
Epoch [ 1020/ 4000] | d_X_loss: 0.2619 | d_Y_loss: 0.2354 | g_total_loss: 3.8481
Epoch [ 1030/ 4000] | d_X_loss: 0.2758 | d_Y_loss: 0.3378 | g_total_loss: 3.3615
Epoch [ 1040/ 4000] | d_X_loss: 0.2855 | d_Y_loss: 0.3260 | g_total_loss: 4.6705
Epoch [ 1050/ 4000] | d_X_loss: 0.3189 | d_Y_loss: 0.7019 | g_total_loss: 4.5748
Epoch [ 1060/ 4000] | d_X_loss: 0.4719 | d_Y_loss: 0.3330 | g_total_loss: 4.9461
Epoch [ 1070/ 4000] | d_X_loss: 0.3268 | d_Y_loss: 0.3631 | g_total_loss: 3.8627
Epoch [ 1080/ 4000] | d_X_loss: 0.2614 | d_Y_loss: 0.2355 | g_total_loss: 5.3780
Epoch [ 1090/ 4000] | d_X_loss: 0.3291 | d_Y_loss: 0.3482 | g_total_loss: 4.2025
Epoch [ 1100/ 4000] | d_X_loss: 0.3453 | d_Y_loss: 0.5367 | g_total_loss: 4.5335
Saved samples_cyclegan\sample-001100-X-Y.png
Saved samples_cyclegan\sample-001100-Y-X.png
Epoch [ 1110/ 4000] | d_X_loss: 0.3302 | d_Y_loss: 0.3931 | g_total_loss: 3.6543
Epoch [ 1120/ 4000] | d_X_loss: 0.3846 | d_Y_loss: 0.3638 | g_total_loss: 4.5692
Epoch [ 1130/ 4000] | d_X_loss: 0.5143 | d_Y_loss: 0.2817 | g_total_loss: 3.9195
Epoch [ 1140/ 4000] | d_X_loss: 0.5760 | d_Y_loss: 0.3604 | g_total_loss: 4.2246
Epoch [ 1150/ 4000] | d_X_loss: 0.4144 | d_Y_loss: 0.3529 | g_total_loss: 3.7904
Epoch [ 1160/ 4000] | d_X_loss: 0.2653 | d_Y_loss: 0.3390 | g_total_loss: 4.3871
Epoch [ 1170/ 4000] | d_X_loss: 0.2558 | d_Y_loss: 0.3547 | g_total_loss: 4.5869
Epoch [ 1180/ 4000] | d_X_loss: 0.3521 | d_Y_loss: 0.3592 | g_total_loss: 3.7955
Epoch [ 1190/ 4000] | d_X_loss: 0.4330 | d_Y_loss: 0.3313 | g_total_loss: 3.5812
Epoch [ 1200/ 4000] | d_X_loss: 0.4655 | d_Y_loss: 0.4537 | g_total_loss: 4.8863
Saved samples_cyclegan\sample-001200-X-Y.png
Saved samples_cyclegan\sample-001200-Y-X.png
Epoch [ 1210/ 4000] | d_X_loss: 0.2834 | d_Y_loss: 0.2879 | g_total_loss: 3.6491
Epoch [ 1220/ 4000] | d_X_loss: 0.2501 | d_Y_loss: 0.2933 | g_total_loss: 4.3030
Epoch [ 1230/ 4000] | d_X_loss: 0.1982 | d_Y_loss: 0.4472 | g_total_loss: 3.5712
Epoch [ 1240/ 4000] | d_X_loss: 0.4431 | d_Y_loss: 0.3398 | g_total_loss: 4.7941
Epoch [ 1250/ 4000] | d_X_loss: 0.3302 | d_Y_loss: 0.4128 | g_total_loss: 3.5984
Epoch [ 1260/ 4000] | d_X_loss: 0.3301 | d_Y_loss: 0.3314 | g_total_loss: 3.8981
Epoch [ 1270/ 4000] | d_X_loss: 0.3672 | d_Y_loss: 0.4180 | g_total_loss: 4.3557
Epoch [ 1280/ 4000] | d_X_loss: 0.4005 | d_Y_loss: 0.2855 | g_total_loss: 5.1825
Epoch [ 1290/ 4000] | d_X_loss: 0.1829 | d_Y_loss: 0.1730 | g_total_loss: 4.1716
Epoch [ 1300/ 4000] | d_X_loss: 0.4089 | d_Y_loss: 0.1965 | g_total_loss: 4.8351
Saved samples_cyclegan\sample-001300-X-Y.png
Saved samples_cyclegan\sample-001300-Y-X.png
Epoch [ 1310/ 4000] | d_X_loss: 0.3169 | d_Y_loss: 0.2017 | g_total_loss: 4.2017
Epoch [ 1320/ 4000] | d_X_loss: 0.3370 | d_Y_loss: 0.1891 | g_total_loss: 3.9147
Epoch [ 1330/ 4000] | d_X_loss: 0.4589 | d_Y_loss: 0.3701 | g_total_loss: 5.1806
Epoch [ 1340/ 4000] | d_X_loss: 0.2244 | d_Y_loss: 0.4014 | g_total_loss: 4.0545
Epoch [ 1350/ 4000] | d_X_loss: 0.2655 | d_Y_loss: 0.2202 | g_total_loss: 3.9451
Epoch [ 1360/ 4000] | d_X_loss: 0.4063 | d_Y_loss: 0.3223 | g_total_loss: 3.0441
Epoch [ 1370/ 4000] | d_X_loss: 0.1867 | d_Y_loss: 0.3139 | g_total_loss: 3.8415
Epoch [ 1380/ 4000] | d_X_loss: 0.5744 | d_Y_loss: 0.5262 | g_total_loss: 5.0445
Epoch [ 1390/ 4000] | d_X_loss: 0.3617 | d_Y_loss: 0.3165 | g_total_loss: 4.0066
Epoch [ 1400/ 4000] | d_X_loss: 0.2844 | d_Y_loss: 0.4570 | g_total_loss: 2.9074
Saved samples_cyclegan\sample-001400-X-Y.png
Saved samples_cyclegan\sample-001400-Y-X.png
Epoch [ 1410/ 4000] | d_X_loss: 0.2246 | d_Y_loss: 0.2911 | g_total_loss: 4.6453
Epoch [ 1420/ 4000] | d_X_loss: 0.4554 | d_Y_loss: 0.3000 | g_total_loss: 3.2865
Epoch [ 1430/ 4000] | d_X_loss: 0.2740 | d_Y_loss: 0.2244 | g_total_loss: 3.5126
Epoch [ 1440/ 4000] | d_X_loss: 0.2226 | d_Y_loss: 0.3450 | g_total_loss: 3.3104
Epoch [ 1450/ 4000] | d_X_loss: 0.3333 | d_Y_loss: 0.2838 | g_total_loss: 4.0078
Epoch [ 1460/ 4000] | d_X_loss: 0.1873 | d_Y_loss: 0.3344 | g_total_loss: 4.9313
Epoch [ 1470/ 4000] | d_X_loss: 0.1317 | d_Y_loss: 0.3042 | g_total_loss: 4.8351
Epoch [ 1480/ 4000] | d_X_loss: 0.1698 | d_Y_loss: 0.3624 | g_total_loss: 3.8868
Epoch [ 1490/ 4000] | d_X_loss: 0.4213 | d_Y_loss: 0.3602 | g_total_loss: 3.8777
Epoch [ 1500/ 4000] | d_X_loss: 0.4345 | d_Y_loss: 0.3313 | g_total_loss: 5.1204
Saved samples_cyclegan\sample-001500-X-Y.png
Saved samples_cyclegan\sample-001500-Y-X.png
Epoch [ 1510/ 4000] | d_X_loss: 0.2793 | d_Y_loss: 0.2256 | g_total_loss: 3.7900
Epoch [ 1520/ 4000] | d_X_loss: 0.1193 | d_Y_loss: 0.2335 | g_total_loss: 4.0588
Epoch [ 1530/ 4000] | d_X_loss: 0.3349 | d_Y_loss: 0.2095 | g_total_loss: 4.9467
Epoch [ 1540/ 4000] | d_X_loss: 0.1193 | d_Y_loss: 0.3117 | g_total_loss: 4.9567
Epoch [ 1550/ 4000] | d_X_loss: 0.3310 | d_Y_loss: 0.2514 | g_total_loss: 3.3441
Epoch [ 1560/ 4000] | d_X_loss: 0.1253 | d_Y_loss: 0.3397 | g_total_loss: 4.0857
Epoch [ 1570/ 4000] | d_X_loss: 0.2927 | d_Y_loss: 0.3746 | g_total_loss: 3.2775
Epoch [ 1580/ 4000] | d_X_loss: 0.4625 | d_Y_loss: 0.2476 | g_total_loss: 4.7023
Epoch [ 1590/ 4000] | d_X_loss: 0.1965 | d_Y_loss: 0.2072 | g_total_loss: 4.2982
Epoch [ 1600/ 4000] | d_X_loss: 0.5512 | d_Y_loss: 0.2222 | g_total_loss: 4.5059
Saved samples_cyclegan\sample-001600-X-Y.png
Saved samples_cyclegan\sample-001600-Y-X.png
Epoch [ 1610/ 4000] | d_X_loss: 0.2913 | d_Y_loss: 0.2523 | g_total_loss: 3.7377
Epoch [ 1620/ 4000] | d_X_loss: 0.3832 | d_Y_loss: 0.2240 | g_total_loss: 3.4926
Epoch [ 1630/ 4000] | d_X_loss: 0.3551 | d_Y_loss: 0.3286 | g_total_loss: 3.8380
Epoch [ 1640/ 4000] | d_X_loss: 0.1770 | d_Y_loss: 0.3470 | g_total_loss: 4.2647
Epoch [ 1650/ 4000] | d_X_loss: 0.1296 | d_Y_loss: 0.3781 | g_total_loss: 4.3879
Epoch [ 1660/ 4000] | d_X_loss: 0.0505 | d_Y_loss: 0.2914 | g_total_loss: 4.1941
Epoch [ 1670/ 4000] | d_X_loss: 0.3420 | d_Y_loss: 0.2404 | g_total_loss: 4.0561
Epoch [ 1680/ 4000] | d_X_loss: 0.1187 | d_Y_loss: 0.2713 | g_total_loss: 4.9625
Epoch [ 1690/ 4000] | d_X_loss: 0.2311 | d_Y_loss: 0.3167 | g_total_loss: 4.5520
Epoch [ 1700/ 4000] | d_X_loss: 0.1519 | d_Y_loss: 0.2551 | g_total_loss: 3.7563
Saved samples_cyclegan\sample-001700-X-Y.png
Saved samples_cyclegan\sample-001700-Y-X.png
Epoch [ 1710/ 4000] | d_X_loss: 0.2057 | d_Y_loss: 0.3143 | g_total_loss: 4.5676
Epoch [ 1720/ 4000] | d_X_loss: 0.2140 | d_Y_loss: 0.2713 | g_total_loss: 3.7492
Epoch [ 1730/ 4000] | d_X_loss: 0.2077 | d_Y_loss: 0.2332 | g_total_loss: 4.4261
Epoch [ 1740/ 4000] | d_X_loss: 0.2145 | d_Y_loss: 0.2203 | g_total_loss: 3.6388
Epoch [ 1750/ 4000] | d_X_loss: 0.1794 | d_Y_loss: 0.3870 | g_total_loss: 6.2496
Epoch [ 1760/ 4000] | d_X_loss: 0.0888 | d_Y_loss: 0.2837 | g_total_loss: 3.8704
Epoch [ 1770/ 4000] | d_X_loss: 0.6851 | d_Y_loss: 0.2815 | g_total_loss: 3.1318
Epoch [ 1780/ 4000] | d_X_loss: 0.3657 | d_Y_loss: 0.1455 | g_total_loss: 3.2457
Epoch [ 1790/ 4000] | d_X_loss: 0.2109 | d_Y_loss: 0.1655 | g_total_loss: 4.4248
Epoch [ 1800/ 4000] | d_X_loss: 0.1846 | d_Y_loss: 0.3636 | g_total_loss: 4.3653
Saved samples_cyclegan\sample-001800-X-Y.png
Saved samples_cyclegan\sample-001800-Y-X.png
Epoch [ 1810/ 4000] | d_X_loss: 0.2516 | d_Y_loss: 0.2265 | g_total_loss: 3.7558
Epoch [ 1820/ 4000] | d_X_loss: 0.2453 | d_Y_loss: 0.2958 | g_total_loss: 4.3307
Epoch [ 1830/ 4000] | d_X_loss: 0.0978 | d_Y_loss: 0.1835 | g_total_loss: 4.9299
Epoch [ 1840/ 4000] | d_X_loss: 0.2532 | d_Y_loss: 0.2218 | g_total_loss: 4.8016
Epoch [ 1850/ 4000] | d_X_loss: 0.3414 | d_Y_loss: 0.2548 | g_total_loss: 4.5427
Epoch [ 1860/ 4000] | d_X_loss: 0.2404 | d_Y_loss: 0.1773 | g_total_loss: 4.8183
Epoch [ 1870/ 4000] | d_X_loss: 0.1979 | d_Y_loss: 0.1350 | g_total_loss: 5.4575
Epoch [ 1880/ 4000] | d_X_loss: 0.2234 | d_Y_loss: 0.3509 | g_total_loss: 3.2798
Epoch [ 1890/ 4000] | d_X_loss: 0.2255 | d_Y_loss: 0.5401 | g_total_loss: 3.8010
Epoch [ 1900/ 4000] | d_X_loss: 0.1627 | d_Y_loss: 0.2118 | g_total_loss: 4.9023
Saved samples_cyclegan\sample-001900-X-Y.png
Saved samples_cyclegan\sample-001900-Y-X.png
Epoch [ 1910/ 4000] | d_X_loss: 0.2245 | d_Y_loss: 0.2161 | g_total_loss: 4.7382
Epoch [ 1920/ 4000] | d_X_loss: 0.1671 | d_Y_loss: 0.2087 | g_total_loss: 4.1246
Epoch [ 1930/ 4000] | d_X_loss: 0.2147 | d_Y_loss: 0.7314 | g_total_loss: 3.7487
Epoch [ 1940/ 4000] | d_X_loss: 0.2209 | d_Y_loss: 0.1580 | g_total_loss: 4.5891
Epoch [ 1950/ 4000] | d_X_loss: 0.2087 | d_Y_loss: 0.1544 | g_total_loss: 3.9374
Epoch [ 1960/ 4000] | d_X_loss: 0.2173 | d_Y_loss: 0.1743 | g_total_loss: 4.9052
Epoch [ 1970/ 4000] | d_X_loss: 0.2447 | d_Y_loss: 0.1332 | g_total_loss: 4.1959
Epoch [ 1980/ 4000] | d_X_loss: 0.2045 | d_Y_loss: 0.1706 | g_total_loss: 4.0144
Epoch [ 1990/ 4000] | d_X_loss: 0.3203 | d_Y_loss: 0.1595 | g_total_loss: 4.7949
Epoch [ 2000/ 4000] | d_X_loss: 0.1781 | d_Y_loss: 0.2051 | g_total_loss: 3.4849
Saved samples_cyclegan\sample-002000-X-Y.png
Saved samples_cyclegan\sample-002000-Y-X.png
Epoch [ 2010/ 4000] | d_X_loss: 0.0972 | d_Y_loss: 0.1107 | g_total_loss: 4.3331
Epoch [ 2020/ 4000] | d_X_loss: 0.0998 | d_Y_loss: 0.2139 | g_total_loss: 3.4415
Epoch [ 2030/ 4000] | d_X_loss: 0.1767 | d_Y_loss: 0.2417 | g_total_loss: 4.3786
Epoch [ 2040/ 4000] | d_X_loss: 0.2211 | d_Y_loss: 0.2456 | g_total_loss: 3.8615
Epoch [ 2050/ 4000] | d_X_loss: 0.2284 | d_Y_loss: 0.1748 | g_total_loss: 3.9135
Epoch [ 2060/ 4000] | d_X_loss: 0.1734 | d_Y_loss: 0.2074 | g_total_loss: 4.4654
Epoch [ 2070/ 4000] | d_X_loss: 0.3125 | d_Y_loss: 0.2245 | g_total_loss: 4.0113
Epoch [ 2080/ 4000] | d_X_loss: 0.1761 | d_Y_loss: 0.1922 | g_total_loss: 4.2929
Epoch [ 2090/ 4000] | d_X_loss: 0.1834 | d_Y_loss: 0.3068 | g_total_loss: 4.4581
Epoch [ 2100/ 4000] | d_X_loss: 0.3064 | d_Y_loss: 0.1566 | g_total_loss: 4.9099
Saved samples_cyclegan\sample-002100-X-Y.png
Saved samples_cyclegan\sample-002100-Y-X.png
Epoch [ 2110/ 4000] | d_X_loss: 0.3921 | d_Y_loss: 0.1616 | g_total_loss: 5.6459
Epoch [ 2120/ 4000] | d_X_loss: 0.1973 | d_Y_loss: 0.1301 | g_total_loss: 4.0600
Epoch [ 2130/ 4000] | d_X_loss: 0.2164 | d_Y_loss: 0.2650 | g_total_loss: 5.0422
Epoch [ 2140/ 4000] | d_X_loss: 0.2460 | d_Y_loss: 0.2440 | g_total_loss: 3.1917
Epoch [ 2150/ 4000] | d_X_loss: 0.2257 | d_Y_loss: 0.2559 | g_total_loss: 3.9630
Epoch [ 2160/ 4000] | d_X_loss: 0.1155 | d_Y_loss: 0.2884 | g_total_loss: 4.9190
Epoch [ 2170/ 4000] | d_X_loss: 0.4145 | d_Y_loss: 0.1827 | g_total_loss: 3.6137
Epoch [ 2180/ 4000] | d_X_loss: 0.1381 | d_Y_loss: 0.1701 | g_total_loss: 3.8473
Epoch [ 2190/ 4000] | d_X_loss: 0.1805 | d_Y_loss: 0.0951 | g_total_loss: 5.4423
Epoch [ 2200/ 4000] | d_X_loss: 0.0960 | d_Y_loss: 0.6222 | g_total_loss: 3.3969
Saved samples_cyclegan\sample-002200-X-Y.png
Saved samples_cyclegan\sample-002200-Y-X.png
Epoch [ 2210/ 4000] | d_X_loss: 0.0744 | d_Y_loss: 0.1270 | g_total_loss: 4.4878
Epoch [ 2220/ 4000] | d_X_loss: 0.0914 | d_Y_loss: 0.2435 | g_total_loss: 4.6932
Epoch [ 2230/ 4000] | d_X_loss: 0.1468 | d_Y_loss: 0.4272 | g_total_loss: 4.1830
Epoch [ 2240/ 4000] | d_X_loss: 0.2494 | d_Y_loss: 0.2015 | g_total_loss: 4.2706
Epoch [ 2250/ 4000] | d_X_loss: 0.1757 | d_Y_loss: 0.1793 | g_total_loss: 3.9683
Epoch [ 2260/ 4000] | d_X_loss: 0.1397 | d_Y_loss: 0.1782 | g_total_loss: 4.5586
Epoch [ 2270/ 4000] | d_X_loss: 0.2616 | d_Y_loss: 0.1131 | g_total_loss: 4.2690
Epoch [ 2280/ 4000] | d_X_loss: 0.1925 | d_Y_loss: 0.0808 | g_total_loss: 3.9416
Epoch [ 2290/ 4000] | d_X_loss: 0.1919 | d_Y_loss: 0.3937 | g_total_loss: 3.5182
Epoch [ 2300/ 4000] | d_X_loss: 0.1131 | d_Y_loss: 0.1391 | g_total_loss: 4.4203
Saved samples_cyclegan\sample-002300-X-Y.png
Saved samples_cyclegan\sample-002300-Y-X.png
Epoch [ 2310/ 4000] | d_X_loss: 0.0990 | d_Y_loss: 0.1307 | g_total_loss: 4.5005
Epoch [ 2320/ 4000] | d_X_loss: 0.1604 | d_Y_loss: 0.1838 | g_total_loss: 3.6223
Epoch [ 2330/ 4000] | d_X_loss: 0.1536 | d_Y_loss: 0.1390 | g_total_loss: 4.8572
Epoch [ 2340/ 4000] | d_X_loss: 0.1343 | d_Y_loss: 0.1084 | g_total_loss: 4.0633
Epoch [ 2350/ 4000] | d_X_loss: 0.1042 | d_Y_loss: 0.1423 | g_total_loss: 3.8809
Epoch [ 2360/ 4000] | d_X_loss: 0.1591 | d_Y_loss: 0.2469 | g_total_loss: 4.0801
Epoch [ 2370/ 4000] | d_X_loss: 0.2808 | d_Y_loss: 0.1191 | g_total_loss: 4.6806
Epoch [ 2380/ 4000] | d_X_loss: 0.1837 | d_Y_loss: 0.3835 | g_total_loss: 4.1460
Epoch [ 2390/ 4000] | d_X_loss: 0.1814 | d_Y_loss: 0.1980 | g_total_loss: 3.9623
Epoch [ 2400/ 4000] | d_X_loss: 0.4033 | d_Y_loss: 0.2625 | g_total_loss: 3.6653
Saved samples_cyclegan\sample-002400-X-Y.png
Saved samples_cyclegan\sample-002400-Y-X.png
Epoch [ 2410/ 4000] | d_X_loss: 0.3460 | d_Y_loss: 0.2326 | g_total_loss: 4.1028
Epoch [ 2420/ 4000] | d_X_loss: 0.4186 | d_Y_loss: 0.1736 | g_total_loss: 4.7079
Epoch [ 2430/ 4000] | d_X_loss: 0.1230 | d_Y_loss: 0.1730 | g_total_loss: 4.0678
Epoch [ 2440/ 4000] | d_X_loss: 0.2902 | d_Y_loss: 0.4360 | g_total_loss: 7.0480
Epoch [ 2450/ 4000] | d_X_loss: 0.1821 | d_Y_loss: 0.1941 | g_total_loss: 3.5136
Epoch [ 2460/ 4000] | d_X_loss: 0.1940 | d_Y_loss: 0.1366 | g_total_loss: 5.2467
Epoch [ 2470/ 4000] | d_X_loss: 0.1099 | d_Y_loss: 0.2758 | g_total_loss: 3.8278
Epoch [ 2480/ 4000] | d_X_loss: 0.0929 | d_Y_loss: 0.1303 | g_total_loss: 3.8676
Epoch [ 2490/ 4000] | d_X_loss: 0.3100 | d_Y_loss: 0.1394 | g_total_loss: 5.2213
Epoch [ 2500/ 4000] | d_X_loss: 0.2059 | d_Y_loss: 0.2532 | g_total_loss: 3.8096
Saved samples_cyclegan\sample-002500-X-Y.png
Saved samples_cyclegan\sample-002500-Y-X.png
Epoch [ 2510/ 4000] | d_X_loss: 0.2380 | d_Y_loss: 0.1905 | g_total_loss: 3.2884
Epoch [ 2520/ 4000] | d_X_loss: 0.1642 | d_Y_loss: 0.1766 | g_total_loss: 4.5622
Epoch [ 2530/ 4000] | d_X_loss: 0.1931 | d_Y_loss: 0.1561 | g_total_loss: 3.6342
Epoch [ 2540/ 4000] | d_X_loss: 0.1450 | d_Y_loss: 0.1860 | g_total_loss: 3.8014
Epoch [ 2550/ 4000] | d_X_loss: 0.2815 | d_Y_loss: 0.1468 | g_total_loss: 3.9087
Epoch [ 2560/ 4000] | d_X_loss: 0.2338 | d_Y_loss: 0.2171 | g_total_loss: 4.0757
Epoch [ 2570/ 4000] | d_X_loss: 0.1915 | d_Y_loss: 0.1811 | g_total_loss: 3.5535
Epoch [ 2580/ 4000] | d_X_loss: 0.1543 | d_Y_loss: 0.1382 | g_total_loss: 4.0835
Epoch [ 2590/ 4000] | d_X_loss: 0.1696 | d_Y_loss: 0.0868 | g_total_loss: 4.2808
Epoch [ 2600/ 4000] | d_X_loss: 0.5235 | d_Y_loss: 0.1571 | g_total_loss: 3.3020
Saved samples_cyclegan\sample-002600-X-Y.png
Saved samples_cyclegan\sample-002600-Y-X.png
Epoch [ 2610/ 4000] | d_X_loss: 0.2354 | d_Y_loss: 0.1561 | g_total_loss: 4.0387
Epoch [ 2620/ 4000] | d_X_loss: 0.1593 | d_Y_loss: 0.1685 | g_total_loss: 4.5139
Epoch [ 2630/ 4000] | d_X_loss: 0.0959 | d_Y_loss: 0.0961 | g_total_loss: 4.5126
Epoch [ 2640/ 4000] | d_X_loss: 0.1869 | d_Y_loss: 0.1330 | g_total_loss: 5.3582
Epoch [ 2650/ 4000] | d_X_loss: 0.2087 | d_Y_loss: 0.1305 | g_total_loss: 3.6522
Epoch [ 2660/ 4000] | d_X_loss: 0.1375 | d_Y_loss: 0.1539 | g_total_loss: 4.7373
Epoch [ 2670/ 4000] | d_X_loss: 0.1635 | d_Y_loss: 0.0970 | g_total_loss: 3.0684
Epoch [ 2680/ 4000] | d_X_loss: 0.1601 | d_Y_loss: 0.1331 | g_total_loss: 5.1923
Epoch [ 2690/ 4000] | d_X_loss: 0.2383 | d_Y_loss: 0.1493 | g_total_loss: 3.7846
Epoch [ 2700/ 4000] | d_X_loss: 0.1319 | d_Y_loss: 0.1597 | g_total_loss: 4.2370
Saved samples_cyclegan\sample-002700-X-Y.png
Saved samples_cyclegan\sample-002700-Y-X.png
Epoch [ 2710/ 4000] | d_X_loss: 0.1263 | d_Y_loss: 0.2058 | g_total_loss: 3.5269
Epoch [ 2720/ 4000] | d_X_loss: 0.2849 | d_Y_loss: 0.0812 | g_total_loss: 4.8655
Epoch [ 2730/ 4000] | d_X_loss: 0.1309 | d_Y_loss: 0.0885 | g_total_loss: 4.7802
Epoch [ 2740/ 4000] | d_X_loss: 0.1506 | d_Y_loss: 0.0981 | g_total_loss: 4.1766
Epoch [ 2750/ 4000] | d_X_loss: 0.1388 | d_Y_loss: 0.1625 | g_total_loss: 4.6989
Epoch [ 2760/ 4000] | d_X_loss: 0.1054 | d_Y_loss: 0.1771 | g_total_loss: 3.9987
Epoch [ 2770/ 4000] | d_X_loss: 0.1714 | d_Y_loss: 0.1176 | g_total_loss: 4.6373
Epoch [ 2780/ 4000] | d_X_loss: 0.1818 | d_Y_loss: 0.1338 | g_total_loss: 3.8682
Epoch [ 2790/ 4000] | d_X_loss: 0.2414 | d_Y_loss: 0.2471 | g_total_loss: 5.2718
Epoch [ 2800/ 4000] | d_X_loss: 0.1918 | d_Y_loss: 0.1207 | g_total_loss: 4.0947
Saved samples_cyclegan\sample-002800-X-Y.png
Saved samples_cyclegan\sample-002800-Y-X.png
Epoch [ 2810/ 4000] | d_X_loss: 0.1574 | d_Y_loss: 0.1709 | g_total_loss: 3.5641
Epoch [ 2820/ 4000] | d_X_loss: 0.2615 | d_Y_loss: 0.1378 | g_total_loss: 3.4653
Epoch [ 2830/ 4000] | d_X_loss: 0.1377 | d_Y_loss: 0.1429 | g_total_loss: 4.2677
Epoch [ 2840/ 4000] | d_X_loss: 0.0965 | d_Y_loss: 0.1815 | g_total_loss: 5.3506
Epoch [ 2850/ 4000] | d_X_loss: 0.0553 | d_Y_loss: 0.1938 | g_total_loss: 4.7695
Epoch [ 2860/ 4000] | d_X_loss: 0.0828 | d_Y_loss: 0.1410 | g_total_loss: 3.8434
Epoch [ 2870/ 4000] | d_X_loss: 0.1348 | d_Y_loss: 0.1393 | g_total_loss: 4.7842
Epoch [ 2880/ 4000] | d_X_loss: 0.1183 | d_Y_loss: 0.2049 | g_total_loss: 3.6714
Epoch [ 2890/ 4000] | d_X_loss: 0.2384 | d_Y_loss: 0.1129 | g_total_loss: 3.8162
Epoch [ 2900/ 4000] | d_X_loss: 0.4245 | d_Y_loss: 0.2034 | g_total_loss: 3.4330
Saved samples_cyclegan\sample-002900-X-Y.png
Saved samples_cyclegan\sample-002900-Y-X.png
Epoch [ 2910/ 4000] | d_X_loss: 0.1708 | d_Y_loss: 0.0805 | g_total_loss: 3.8404
Epoch [ 2920/ 4000] | d_X_loss: 0.1370 | d_Y_loss: 0.1101 | g_total_loss: 4.3013
Epoch [ 2930/ 4000] | d_X_loss: 0.1535 | d_Y_loss: 0.6554 | g_total_loss: 4.9101
Epoch [ 2940/ 4000] | d_X_loss: 0.2052 | d_Y_loss: 0.1635 | g_total_loss: 4.3911
Epoch [ 2950/ 4000] | d_X_loss: 0.1237 | d_Y_loss: 0.2385 | g_total_loss: 4.6740
Epoch [ 2960/ 4000] | d_X_loss: 0.2703 | d_Y_loss: 0.0918 | g_total_loss: 3.7624
Epoch [ 2970/ 4000] | d_X_loss: 0.1934 | d_Y_loss: 0.1257 | g_total_loss: 3.8371
Epoch [ 2980/ 4000] | d_X_loss: 0.1121 | d_Y_loss: 0.1215 | g_total_loss: 3.9961
Epoch [ 2990/ 4000] | d_X_loss: 0.1102 | d_Y_loss: 0.1735 | g_total_loss: 4.2916
Epoch [ 3000/ 4000] | d_X_loss: 0.1171 | d_Y_loss: 0.1116 | g_total_loss: 5.3242
Saved samples_cyclegan\sample-003000-X-Y.png
Saved samples_cyclegan\sample-003000-Y-X.png
Epoch [ 3010/ 4000] | d_X_loss: 0.1382 | d_Y_loss: 0.2450 | g_total_loss: 4.7587
Epoch [ 3020/ 4000] | d_X_loss: 0.2495 | d_Y_loss: 0.1103 | g_total_loss: 3.9855
Epoch [ 3030/ 4000] | d_X_loss: 0.3529 | d_Y_loss: 0.1092 | g_total_loss: 4.5986
Epoch [ 3040/ 4000] | d_X_loss: 0.2288 | d_Y_loss: 0.0972 | g_total_loss: 3.6740
Epoch [ 3050/ 4000] | d_X_loss: 0.2723 | d_Y_loss: 0.0888 | g_total_loss: 3.9272
Epoch [ 3060/ 4000] | d_X_loss: 0.1720 | d_Y_loss: 0.2230 | g_total_loss: 3.4058
Epoch [ 3070/ 4000] | d_X_loss: 0.0981 | d_Y_loss: 0.0973 | g_total_loss: 4.0955
Epoch [ 3080/ 4000] | d_X_loss: 0.1311 | d_Y_loss: 0.1665 | g_total_loss: 4.4432
Epoch [ 3090/ 4000] | d_X_loss: 0.3892 | d_Y_loss: 0.2444 | g_total_loss: 4.7090
Epoch [ 3100/ 4000] | d_X_loss: 0.2150 | d_Y_loss: 0.2719 | g_total_loss: 3.8034
Saved samples_cyclegan\sample-003100-X-Y.png
Saved samples_cyclegan\sample-003100-Y-X.png
Epoch [ 3110/ 4000] | d_X_loss: 0.1340 | d_Y_loss: 0.2168 | g_total_loss: 4.6267
Epoch [ 3120/ 4000] | d_X_loss: 0.1718 | d_Y_loss: 0.1304 | g_total_loss: 4.6149
Epoch [ 3130/ 4000] | d_X_loss: 0.1262 | d_Y_loss: 0.1089 | g_total_loss: 4.2572
Epoch [ 3140/ 4000] | d_X_loss: 0.1042 | d_Y_loss: 0.1657 | g_total_loss: 4.2591
Epoch [ 3150/ 4000] | d_X_loss: 0.2266 | d_Y_loss: 0.1527 | g_total_loss: 3.5689
Epoch [ 3160/ 4000] | d_X_loss: 0.1489 | d_Y_loss: 0.0812 | g_total_loss: 3.8973
Epoch [ 3170/ 4000] | d_X_loss: 0.2193 | d_Y_loss: 0.3287 | g_total_loss: 3.7501
Epoch [ 3180/ 4000] | d_X_loss: 0.1012 | d_Y_loss: 0.1164 | g_total_loss: 4.4795
Epoch [ 3190/ 4000] | d_X_loss: 0.1524 | d_Y_loss: 0.2016 | g_total_loss: 3.2164
Epoch [ 3200/ 4000] | d_X_loss: 0.1676 | d_Y_loss: 0.0773 | g_total_loss: 3.9719
Saved samples_cyclegan\sample-003200-X-Y.png
Saved samples_cyclegan\sample-003200-Y-X.png
Epoch [ 3210/ 4000] | d_X_loss: 0.3050 | d_Y_loss: 0.0757 | g_total_loss: 5.5718
Epoch [ 3220/ 4000] | d_X_loss: 0.0786 | d_Y_loss: 0.1657 | g_total_loss: 5.0780
Epoch [ 3230/ 4000] | d_X_loss: 0.0496 | d_Y_loss: 0.0981 | g_total_loss: 3.8953
Epoch [ 3240/ 4000] | d_X_loss: 0.0890 | d_Y_loss: 0.0732 | g_total_loss: 4.2220
Epoch [ 3250/ 4000] | d_X_loss: 0.1440 | d_Y_loss: 0.0894 | g_total_loss: 4.0683
Epoch [ 3260/ 4000] | d_X_loss: 0.0403 | d_Y_loss: 0.2158 | g_total_loss: 3.5175
Epoch [ 3270/ 4000] | d_X_loss: 0.1792 | d_Y_loss: 0.0749 | g_total_loss: 4.8576
Epoch [ 3280/ 4000] | d_X_loss: 0.1268 | d_Y_loss: 0.1751 | g_total_loss: 4.8497
Epoch [ 3290/ 4000] | d_X_loss: 0.3649 | d_Y_loss: 0.1971 | g_total_loss: 4.8196
Epoch [ 3300/ 4000] | d_X_loss: 0.1289 | d_Y_loss: 0.0892 | g_total_loss: 4.2846
Saved samples_cyclegan\sample-003300-X-Y.png
Saved samples_cyclegan\sample-003300-Y-X.png
Epoch [ 3310/ 4000] | d_X_loss: 0.1311 | d_Y_loss: 0.1027 | g_total_loss: 4.2764
Epoch [ 3320/ 4000] | d_X_loss: 0.2549 | d_Y_loss: 0.0669 | g_total_loss: 4.2704
Epoch [ 3330/ 4000] | d_X_loss: 0.0732 | d_Y_loss: 0.1354 | g_total_loss: 3.3455
Epoch [ 3340/ 4000] | d_X_loss: 0.1357 | d_Y_loss: 0.0963 | g_total_loss: 4.6313
Epoch [ 3350/ 4000] | d_X_loss: 0.1495 | d_Y_loss: 0.1286 | g_total_loss: 4.4231
Epoch [ 3360/ 4000] | d_X_loss: 0.1493 | d_Y_loss: 0.1293 | g_total_loss: 4.9910
Epoch [ 3370/ 4000] | d_X_loss: 0.1904 | d_Y_loss: 0.1174 | g_total_loss: 4.3939
Epoch [ 3380/ 4000] | d_X_loss: 0.0974 | d_Y_loss: 0.2250 | g_total_loss: 4.1682
Epoch [ 3390/ 4000] | d_X_loss: 0.0968 | d_Y_loss: 0.0772 | g_total_loss: 4.1485
Epoch [ 3400/ 4000] | d_X_loss: 0.1014 | d_Y_loss: 0.1089 | g_total_loss: 3.8678
Saved samples_cyclegan\sample-003400-X-Y.png
Saved samples_cyclegan\sample-003400-Y-X.png
Epoch [ 3410/ 4000] | d_X_loss: 0.2475 | d_Y_loss: 0.2502 | g_total_loss: 6.1469
Epoch [ 3420/ 4000] | d_X_loss: 0.0989 | d_Y_loss: 0.1497 | g_total_loss: 3.4511
Epoch [ 3430/ 4000] | d_X_loss: 0.1952 | d_Y_loss: 0.1830 | g_total_loss: 5.1777
Epoch [ 3440/ 4000] | d_X_loss: 0.1683 | d_Y_loss: 0.2016 | g_total_loss: 3.9492
Epoch [ 3450/ 4000] | d_X_loss: 0.0918 | d_Y_loss: 0.0593 | g_total_loss: 4.5958
Epoch [ 3460/ 4000] | d_X_loss: 0.0678 | d_Y_loss: 0.0954 | g_total_loss: 3.7927
Epoch [ 3470/ 4000] | d_X_loss: 0.2089 | d_Y_loss: 0.0920 | g_total_loss: 4.4103
Epoch [ 3480/ 4000] | d_X_loss: 0.1747 | d_Y_loss: 0.1850 | g_total_loss: 4.0348
Epoch [ 3490/ 4000] | d_X_loss: 0.0693 | d_Y_loss: 0.1268 | g_total_loss: 3.9200
Epoch [ 3500/ 4000] | d_X_loss: 0.1774 | d_Y_loss: 0.1383 | g_total_loss: 4.0009
Saved samples_cyclegan\sample-003500-X-Y.png
Saved samples_cyclegan\sample-003500-Y-X.png
Epoch [ 3510/ 4000] | d_X_loss: 0.1138 | d_Y_loss: 0.1051 | g_total_loss: 4.6092
Epoch [ 3520/ 4000] | d_X_loss: 0.0934 | d_Y_loss: 0.1380 | g_total_loss: 3.5023
Epoch [ 3530/ 4000] | d_X_loss: 0.0877 | d_Y_loss: 0.1549 | g_total_loss: 4.6459
Epoch [ 3540/ 4000] | d_X_loss: 0.1615 | d_Y_loss: 0.1462 | g_total_loss: 4.4218
Epoch [ 3550/ 4000] | d_X_loss: 0.1690 | d_Y_loss: 0.0803 | g_total_loss: 3.8207
Epoch [ 3560/ 4000] | d_X_loss: 0.0975 | d_Y_loss: 0.1501 | g_total_loss: 4.2767
Epoch [ 3570/ 4000] | d_X_loss: 0.0794 | d_Y_loss: 0.2137 | g_total_loss: 3.6586
Epoch [ 3580/ 4000] | d_X_loss: 0.1813 | d_Y_loss: 0.0614 | g_total_loss: 4.0570
Epoch [ 3590/ 4000] | d_X_loss: 0.1093 | d_Y_loss: 0.0932 | g_total_loss: 4.0222
Epoch [ 3600/ 4000] | d_X_loss: 0.0595 | d_Y_loss: 0.0661 | g_total_loss: 4.5487
Saved samples_cyclegan\sample-003600-X-Y.png
Saved samples_cyclegan\sample-003600-Y-X.png
Epoch [ 3610/ 4000] | d_X_loss: 0.1499 | d_Y_loss: 0.1582 | g_total_loss: 3.7410
Epoch [ 3620/ 4000] | d_X_loss: 0.2624 | d_Y_loss: 0.0489 | g_total_loss: 4.9547
Epoch [ 3630/ 4000] | d_X_loss: 0.0855 | d_Y_loss: 0.0792 | g_total_loss: 3.9280
Epoch [ 3640/ 4000] | d_X_loss: 0.0592 | d_Y_loss: 0.1116 | g_total_loss: 4.1779
Epoch [ 3650/ 4000] | d_X_loss: 0.1059 | d_Y_loss: 0.0853 | g_total_loss: 4.2682
Epoch [ 3660/ 4000] | d_X_loss: 0.0807 | d_Y_loss: 0.1411 | g_total_loss: 4.2824
Epoch [ 3670/ 4000] | d_X_loss: 0.3958 | d_Y_loss: 0.2208 | g_total_loss: 6.2076
Epoch [ 3680/ 4000] | d_X_loss: 0.0863 | d_Y_loss: 0.1405 | g_total_loss: 4.6235
Epoch [ 3690/ 4000] | d_X_loss: 0.0628 | d_Y_loss: 0.0543 | g_total_loss: 4.8165
Epoch [ 3700/ 4000] | d_X_loss: 0.1543 | d_Y_loss: 0.1653 | g_total_loss: 4.0814
Saved samples_cyclegan\sample-003700-X-Y.png
Saved samples_cyclegan\sample-003700-Y-X.png
Epoch [ 3710/ 4000] | d_X_loss: 0.1668 | d_Y_loss: 0.1114 | g_total_loss: 4.7814
Epoch [ 3720/ 4000] | d_X_loss: 0.1177 | d_Y_loss: 0.0958 | g_total_loss: 6.2642
Epoch [ 3730/ 4000] | d_X_loss: 0.0837 | d_Y_loss: 0.0944 | g_total_loss: 4.5410
Epoch [ 3740/ 4000] | d_X_loss: 0.1234 | d_Y_loss: 0.1045 | g_total_loss: 4.6872
Epoch [ 3750/ 4000] | d_X_loss: 0.1785 | d_Y_loss: 0.0668 | g_total_loss: 3.4338
Epoch [ 3760/ 4000] | d_X_loss: 0.1590 | d_Y_loss: 0.1128 | g_total_loss: 4.3325
Epoch [ 3770/ 4000] | d_X_loss: 0.1211 | d_Y_loss: 0.2650 | g_total_loss: 3.6643
Epoch [ 3780/ 4000] | d_X_loss: 0.0763 | d_Y_loss: 0.0847 | g_total_loss: 3.9040
Epoch [ 3790/ 4000] | d_X_loss: 0.0678 | d_Y_loss: 0.0997 | g_total_loss: 3.6663
Epoch [ 3800/ 4000] | d_X_loss: 0.0921 | d_Y_loss: 0.0578 | g_total_loss: 4.2542
Saved samples_cyclegan\sample-003800-X-Y.png
Saved samples_cyclegan\sample-003800-Y-X.png
Epoch [ 3810/ 4000] | d_X_loss: 0.1786 | d_Y_loss: 0.0476 | g_total_loss: 4.3553
Epoch [ 3820/ 4000] | d_X_loss: 0.0596 | d_Y_loss: 0.0539 | g_total_loss: 4.2382
Epoch [ 3830/ 4000] | d_X_loss: 0.2400 | d_Y_loss: 0.2008 | g_total_loss: 3.3002
Epoch [ 3840/ 4000] | d_X_loss: 0.1562 | d_Y_loss: 0.1597 | g_total_loss: 3.6673
Epoch [ 3850/ 4000] | d_X_loss: 0.1130 | d_Y_loss: 0.0938 | g_total_loss: 4.1942
Epoch [ 3860/ 4000] | d_X_loss: 0.1316 | d_Y_loss: 0.1411 | g_total_loss: 4.4913
Epoch [ 3870/ 4000] | d_X_loss: 0.1337 | d_Y_loss: 0.1014 | g_total_loss: 4.1584
Epoch [ 3880/ 4000] | d_X_loss: 0.0757 | d_Y_loss: 0.0751 | g_total_loss: 4.2498
Epoch [ 3890/ 4000] | d_X_loss: 0.1773 | d_Y_loss: 0.0741 | g_total_loss: 4.3786
Epoch [ 3900/ 4000] | d_X_loss: 0.1343 | d_Y_loss: 0.0981 | g_total_loss: 5.0021
Saved samples_cyclegan\sample-003900-X-Y.png
Saved samples_cyclegan\sample-003900-Y-X.png
Epoch [ 3910/ 4000] | d_X_loss: 0.0694 | d_Y_loss: 0.2113 | g_total_loss: 4.6867
Epoch [ 3920/ 4000] | d_X_loss: 0.0517 | d_Y_loss: 0.1190 | g_total_loss: 3.7577
Epoch [ 3930/ 4000] | d_X_loss: 0.0942 | d_Y_loss: 0.0803 | g_total_loss: 4.8892
Epoch [ 3940/ 4000] | d_X_loss: 0.0402 | d_Y_loss: 0.0967 | g_total_loss: 4.5235
Epoch [ 3950/ 4000] | d_X_loss: 0.3447 | d_Y_loss: 0.2564 | g_total_loss: 5.4606
Epoch [ 3960/ 4000] | d_X_loss: 0.1026 | d_Y_loss: 0.0812 | g_total_loss: 4.1758
Epoch [ 3970/ 4000] | d_X_loss: 0.1074 | d_Y_loss: 0.1420 | g_total_loss: 4.2914
Epoch [ 3980/ 4000] | d_X_loss: 0.1153 | d_Y_loss: 0.0742 | g_total_loss: 4.1977
Epoch [ 3990/ 4000] | d_X_loss: 0.0672 | d_Y_loss: 0.1218 | g_total_loss: 4.3182
Epoch [ 4000/ 4000] | d_X_loss: 0.1499 | d_Y_loss: 0.0984 | g_total_loss: 4.2634
Saved samples_cyclegan\sample-004000-X-Y.png
Saved samples_cyclegan\sample-004000-Y-X.png

Tips on Training and Loss Patterns

A lot of experimentation goes into finding the best hyperparameters such that the generators and discriminators don't overpower each other. It's often a good starting point to look at existing papers to find what has worked in previous experiments, I'd recommend this DCGAN paper in addition to the original CycleGAN paper to see what worked for them. Then, you can try your own experiments based off of a good foundation.

Discriminator Losses

When you display the generator and discriminator losses you should see that there is always some discriminator loss; recall that we are trying to design a model that can generate good "fake" images. So, the ideal discriminator will not be able to tell the difference between real and fake images and, as such, will always have some loss. You should also see that $D_X$ and $D_Y$ are roughly at the same loss levels; if they are not, this indicates that your training is favoring one type of discriminator over the and you may need to look at biases in your models or data.

Generator Loss

The generator's loss should start significantly higher than the discriminator losses because it is accounting for the loss of both generators and weighted reconstruction errors. You should see this loss decrease a lot at the start of training because initial, generated images are often far-off from being good fakes. After some time it may level off; this is normal since the generator and discriminator are both improving as they train. If you see that the loss is jumping around a lot, over time, you may want to try decreasing your learning rates or changing your cycle consistency loss to be a little more/less weighted.

In [23]:
fig, ax = plt.subplots(figsize=(12,8))
losses = np.array(losses)
plt.plot(losses.T[0], label='Discriminator, X', alpha=0.5)
plt.plot(losses.T[1], label='Discriminator, Y', alpha=0.5)
plt.plot(losses.T[2], label='Generators', alpha=0.5)
plt.title("Training Losses")
plt.legend()
Out[23]:
<matplotlib.legend.Legend at 0x285967c7dd8>

Evaluate the Result!

As you trained this model, you may have chosen to sample and save the results of your generated images after a certain number of training iterations. This gives you a way to see whether or not your Generators are creating good fake images. For example, the image below depicts real images in the $Y$ set, and the corresponding generated images during different points in the training process. You can see that the generator starts out creating very noisy, fake images, but begins to converge to better representations as it trains (though, not perfect).

Below, you've been given a helper function for displaying generated samples based on the passed in training iteration.

In [24]:
import matplotlib.image as mpimg

# helper visualization code
def view_samples(iteration, sample_dir='samples_cyclegan'):
    
    # samples are named by iteration
    path_XtoY = os.path.join(sample_dir, 'sample-{:06d}-X-Y.png'.format(iteration))
    path_YtoX = os.path.join(sample_dir, 'sample-{:06d}-Y-X.png'.format(iteration))
    
    # read in those samples
    try: 
        x2y = mpimg.imread(path_XtoY)
        y2x = mpimg.imread(path_YtoX)
    except:
        print('Invalid number of iterations.')
    
    fig, (ax1, ax2) = plt.subplots(figsize=(18,20), nrows=2, ncols=1, sharey=True, sharex=True)
    ax1.imshow(x2y)
    ax1.set_title('X to Y')
    ax2.imshow(y2x)
    ax2.set_title('Y to X')
In [25]:
# view samples at iteration 100
view_samples(100, 'samples_cyclegan')
In [27]:
# view samples at iteration 1000
view_samples(4000, 'samples_cyclegan')

Further Challenges and Directions

  • One shortcoming of this model is that it produces fairly low-resolution images; this is an ongoing area of research; you can read about a higher-resolution formulation that uses a multi-scale generator model, in this paper.
  • Relatedly, we may want to process these as larger (say 256x256) images at first, to take advantage of high-res data.
  • It may help your model to converge faster, if you initialize the weights in your network.
  • This model struggles with matching colors exactly. This is because, if $G_{YtoX}$ and $G_{XtoY}$ may change the tint of an image; the cycle consistency loss may not be affected and can still be small. You could choose to introduce a new, color-based loss term that compares $G_{YtoX}(y)$ and $y$, and $G_{XtoY}(x)$ and $x$, but then this becomes a supervised learning approach.
  • This unsupervised approach also struggles with geometric changes, like changing the apparent size of individual object in an image, so it is best suited for stylistic transformations.
  • For creating different kinds of models or trying out the Pix2Pix Architecture, this Github repository which implements CycleGAN and Pix2Pix in PyTorch is a great resource.

Once you are satified with your model, you are ancouraged to test it on a different dataset to see if it can find different types of mappings!


Different datasets for download

You can download a variety of datasets used in the Pix2Pix and CycleGAN papers, by following instructions in the associated Github repository. You'll just need to make sure that the data directories are named and organized correctly to load in that data.